#include<stack>
#include<iostream>
using namespace std;
int main(){
	int N1,N2,i,e,size;
	char s; 
	stack<int>S1,S2;
	cin>>N1>>N2;
	if(N1>N2) N1=N2;
	while(cin>>s,s!='T'){
		if(s=='A'){
			cin>>e;
		  if(S1.size()==N1){
			if(S2.size()>0){
				cout<<"ERROR:Full"<<endl;
				continue;
			}
		    for(i=0;i<N1;i++){          
			   S2.push(S1.top());
			   S1.pop();
		     }
	      }
		  if(S1.size()<N1) S1.push(e);
		  else{
			   cout<<"ERROR:Full"<<endl;
			   continue;
		  }
	    }
	    else if(s=='D'){
	    if(S2.size()==0){
	    
	 	  if(S1.size()==0){
	 		{
	 			cout<<"ERROR:Empty"<<endl;
	 			continue;
	 		} 	
	 	  }
	 	    size=S1.size();
	 		for(i=0;i<size;i++){              
	 				S2.push(S1.top());
	 				S1.pop();
	 			}
		  }
			cout<<S2.top()<<endl;
	 		S2.pop();
	    }
	}
	return 0;
}

